#include<bits/stdc++.h>
#define N 100010
using namespace std;
int t;
int n,m,L,V;
int d[N],v[N],a[N],p[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    int cnt=0;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>L>>V;
        for(int j=1;j<=n;j++){
            cin>>d[j]>>v[j]>>a[j];
        }
        for(int j=1;j<=m;j++){
            cin>>p[j];
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0){
            if(v[i]>V&&d[i]<p[m]){
                cnt++;
            }
        }
        if(a[i]>0){
            if(v[i]>V&&d[i]<p[m]){
                cnt++;
            }
        }
        if(a[i]<0){
            if(v[i]>V&&d[i]<p[m]){
                cnt++;
            }
        }
    }
    cout<<cnt;
    return 0;
}
